package com.mspbots.api.service.impl;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.mspbots.api.service.TenantUserService;
import com.mspbots.cw.request.TenantUserDTO;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

import java.util.List;

/**
 * com.mspbots.api.service.TenantUserImpl
 *
 * @author Alex bob(https://github.com/vnobo)
 * @date Created by 2019/6/19
 */
@Deprecated
@Service
public class TenantUserServiceImpl extends BaseGenericService implements TenantUserService {

    @Override
    public List<TenantUserDTO> addBatch(List<TenantUserDTO> tenantUsers) {
        Mono<JsonNode> resultMono = this.apiClient.post("/tenant/user/add-batch", tenantUsers);
        JsonNode result = resultMono.block();
        tenantUsers = this.objectMapper.convertValue(result, new TypeReference<List<TenantUserDTO>>() {
        });
        return tenantUsers;
    }

    @Override
    public TenantUserDTO findById(long id) {
        Mono<JsonNode> resultMono = this.apiClient.get("/tenant/user/" + id + "/info");
        JsonNode result = resultMono.block();
        return this.objectMapper.convertValue(result, TenantUserDTO.class);
    }

    @Override
    public TenantUserDTO findByLastOne(long tenantId) {
        Mono<JsonNode> resultMono = this.apiClient.get(tenantId + "/user/last-one");
        JsonNode result = resultMono.block();
        return this.objectMapper.convertValue(result, TenantUserDTO.class);
    }
}
